package main

import (
	"fmt"
	"strconv"
)

func myAtoi(s string) int {
	s1 := ""
	fuhao := 1
	if (s[0] >= 65 && s[0] <= 90) || (s[0] >= 97 && s[0] <= 122) {
		return 0
	}
cr:
	for i := 0; i < len(s); i++ {
		if (s[i] >= 65 && s[i] <= 90) || (s[i] >= 97 && s[i] <= 122) {
			break
		} else if s[i] >= 48 && s[i] <= 57 {
			for a := i; a < len(s); a++ {
				if s[a] >= 48 && s[a] <= 57 {
					s1 += string(s[a])
				} else {
					break cr
				}
				if a == len(s)-1 {
					break cr
				}
			}
		} else if (s[i] == 43 || s[i] == 45 || s[i] == 20) && len(s1) != 0 { // 加号
			continue
		} else if s[i] == 45 { // 负号
			fuhao = -1
		} else if s[i] == 43 { // 加号
			continue
		} else if s[i] == 20 { // 空格
			continue
		}
	}

	num, _ := strconv.Atoi(s1)
	if num*fuhao < -2147483648 {
		return -2147483648
	}
	if num > 2147483648-1 {
		return 2147483648 - 1
	}
	return num * fuhao
}

func main() {
	fmt.Println(myAtoi("-91283472332"))

	//s := "aZAz"
	//fmt.Println(s[0])
	//fmt.Println(s[1])
	//fmt.Println(s[2])
	//fmt.Println(s[3])
	//fmt.Println(string('90'))

}
